/*-------------------<-- Start of Description-->---------------------\
| Print out a manual for the function specified; |
| Note: The user defined macros must be saved under SASauto path (the|
| path must be in the format of "C:...\MyOwnSetting\sasmacro\";|
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|-----------<-- Start of Files or Arguements Needed-->---------------|
| Arguments: |
| function - the name of the function you want help with; |
| Note: Only User defined sas macros have manuals; |
|-----------------<-- End of Arguements Needed-->--------------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %help(genreadme); |
| Usage: %help(function); |
\-------------------<-- End of Files Created-->---------------------*/
%macro help/parmbuff;
/*--------------------------------------------\
| Copy Right: Duo Zhou; |
| Created: 12-25-2001 2:13pm; |
| Modified: 12-25-2001 10:14am; |
| Purpose: print a manual for user defined |
| function; |
\--------------------------------------------*/
%local _linesize _pagesize ndir dir mydir directory ddir dirrc psid dirrf _tmplast_;
%let _tmplast_=&syslast; %let function=; %let keyword=;
%let _linesize = %SYSFUNC(GETOPTION(linesize)); %let _pagesize = %SYSFUNC(GETOPTION(pagesize));
options ps=1024 ls=256 nocenter;
%let syspbuff=%sysfunc(translate(%quote(%substr(%quote(%trim(%quote(%left(%quote(&syspbuff))))), 2, %eval(%length(%trim(%quote(%left(%quote(&syspbuff)))))-2))), %str(%'), %str(%")));
%let _helpcnt_=0;
%do %while(%length(%nrbquote(%scan(%nrbquote(&syspbuff), %eval(&_helpcnt_+1), %nrbquote(,)))));
%let _helpcnt_=%eval(&_helpcnt_+1);
%let _helpword_=%nrbquote(%qscan(%nrbquote(&syspbuff), &_helpcnt_, %nrbquote(,)));
%if (&_helpcnt_=1) %then %let function=&_helpword_;
%else %let keyword=&_helpword_;
%end;
%let function=%sysfunc(dequote(&function)); %let file=%trim(%left(&function)).sas;
%put --> Note: Looking for manuals (&file) for function &function..;
%let sasatpth=%sysfunc(pathname(sasautos));
%let ndir=1; %let dir=%qscan(&sasatpth, &ndir, %str(()''"")); %let directory=;
%if (%index(%upcase(&dir),%quote(:\))) %then %do;
%let mydir=&dir;
%if (%quote(%substr(&mydir, %length(&mydir), 1)) ne %quote(\)) %then %do;
%let mydir=&mydir.\;
%if (%sysfunc(fileexist(&mydir.&file))) %then %do;
%let directory=&mydir;
%end;
%end;
%end;
%do %while(%length(&dir)>0);
%let ndir=%eval(&ndir+1);
%let dir=%qscan(&sasatpth, &ndir, %str(()''""));
%if (%index(%upcase(&dir),%quote(:\))) %then %do;
%let mydir=&dir;
%if (%quote(%substr(&mydir, %length(&mydir), 1)) ne %quote(\)) %then %do;
%let mydir=&mydir.\;
%if (%sysfunc(fileexist(&mydir.&file))) %then %do;
%let directory=&mydir;
%end;
%end;
%end;
%end;
%if (%quote(&directory) ne) %then %do;
%put --> Note: User defined sas macros are saved under: ;
%put --> "&directory".;
%end;
%else %do;
%put ==> Alert! Cannot find manuals for function &function..;
%goto finish;
%end;
%let ddir=%substr(&directory, 1, %eval(%length(&directory)-1));
%let dirrc=%sysfunc(filename(dirrf,&directory)); %let psid=%sysfunc(DOPEN(&dirrf));
%if &psid %then %do;
%let dirrc=%sysfunc(DCLOSE(&psid));
%let dirrc=%sysfunc(filename(dirrf));
/** Get some information available only to sas system **/
data _tmp2;
length foption $ 200 charval $ 400;
keep memname foption charval;
rc=filename("mydir","&directory");
did=dopen("mydir");
memcount=dnum(did);
do i=1 to memcount;
memname=dread(did,i);
rc=FILENAME("myfile", "&directory"||trimn(left(memname)));
fid = FOPEN("myfile"); /* open file */
foption=" ";
charval=" ";
if fid>0 then do;
numopts=FOPTNUM(fid); /* get number of information items */
do k=1 to numopts;
option = FOPTNAME(fid,k);
if trim(left(foption)) ne " " then do;
foption = trimn(left(foption))||", "||option;
if not index(upcase(FINFO(fid,upcase(option))), upcase("&ddir")) then do;
if trim(left(charval)) ne " " then
charval = trimn(left(charval))||", "||FINFO(fid,upcase(option));
else charval = FINFO(fid,upcase(option));
end;
end;
else do;
foption = option;
if not index(upcase(FINFO(fid,upcase(option))), upcase("&ddir")) then
charval = FINFO(fid,upcase(option));
end;
end;
end;
else do;
numopts=doptnum(did);
if not missing(numopts) then do;
do k=1 to numopts;
option=doptname(did,k);
if trim(left(foption)) ne " " then do;
foption = trimn(left(foption))||", "||option;
if not index(upcase(dinfo(did,upcase(option))), upcase("&ddir")) then do;
if trim(left(charval)) ne " " then
charval=trimn(left(charval))||", "||dinfo(did,upcase(option));
else charval = FINFO(fid,upcase(option));
end;
end;
else do;
foption = option;
if not index(upcase(dinfo(did,upcase(option))), upcase("&ddir")) then
charval = dINFO(did,upcase(option));
end;
end;
end;
end;
rc = FCLOSE(fid); /* close file */
rc = FILENAME("myfile");
if indexw(upcase(foption), 'DIRECTORY') then memname=trimn(left("<"||memname))||">";
output;
end;
label memname="Member Name" foption="Member Type" charval="Member Info";
run;
proc sort data=_tmp2 out=_dirtmp; by memname; run;
proc datasets library=work nolist;
delete _tmp1 _tmp2;
run;quit;
data _tmp3;
set _dirtmp;
if indexw(upcase(memname), upcase("&file"));
run;
%if %nobs(_tmp3) %then %do;
DATA _tmp4;
length fileloc $ 300 line $ 200;
set _tmp3;
by memname;
line='';
fileloc="&directory"||trim(left(memname));
infile dummy length=linelen filename=memname end=done filevar=fileloc;
do while((not done) %if (^%index(%upcase(&keyword), A)) %then and (index(line, ';') ne length(line)););
input @1 line $ varying200. linelen; put line=;
output;
end;
keep line;
label line='Help';
run;
proc print data=_tmp4 noobs label;
title "The Manual For Function %nrstr(%%)&function:";
run; title " ";
proc datasets library=work nolist;
delete _tmp4;
run;quit;
%end;
%else %do;
%put ==> Alert! Can not find function "&function", please provide a valid function name!;
%end;
proc datasets library=work nolist;
delete _dirtmp _tmp3;
run;quit;
%end;
%else %put ==> Alert! The directory "directory" does%str(%')t exist.;
%finish:
options ps=&_pagesize ls=&_linesize;
%let syslast=&_tmplast_;
%mend help;